#!/usr/bin/bash
#
# Put customizations to your image in this file.

PATH=/opt/local/gnu/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin

# Exit if any commands fail
set -o errexit

#binary_bath_url="https://minio.itime.biz:4443/downloads/nexus/"
#http://download.sonatype.com/nexus/3/
binary_bath_url="https://ciapc.wiz.top:8011/tools"

nexus_ver=3.70.4-02
#nexus_binary_file="nexus-${nexus_ver}-unix.tar.gz"
nexus_binary_file="nexus-${nexus_ver}-java8-unix.tar.gz"
#nexus_binary_file="nexus-${nexus_ver}-linux-x86_64.tar.gz"


# Configuring image specific packages
echo "* Configuring image specific packages.";
wget --no-check-certificate ${binary_bath_url}/${nexus_binary_file} -O /root/${nexus_binary_file}
gtar xzf /root/${nexus_binary_file} -C /opt 

echo "* Create ssl folder for nginx"
mkdir /opt/local/etc/nginx/ssl

# link nexus
ln -s /opt/nexus-${nexus_ver} /opt/nexus

/usr/sbin/groupadd -g 200 nexus
/usr/sbin/useradd -u 200 -g nexus -d /home/nexus -s /usr/bin/false nexus
mkdir -p /home/nexus
chown -R nexus:nexus /home/nexus

echo "* Cleanup home/admin because of delegate dataset usage"
rm -rf /home/admin/.[^.]*

# Clean up
echo "* Cleaning up."
rm -rf /root/*

# Prepare image for provisioning
sm-prepare-image -y
